<?php
	error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING );
	$array_items=array();
?>

<table cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td align="left" class='header' height="25px" > 
<a href="/" class="home" title="Home">&nbsp;Home</a><span class="mark">&nbsp;&raquo;&nbsp;</span> <span class="home">Order complete</span> 
</td>
</tr>
<tr>
	<td colspan="1">&nbsp; </td>
</tr>
</tbody>
</table>
<table width="100%" cellspacing="0" cellpadding="5" border="0" class="action">
   <tbody>
	<tr>
		<td id="heading" class="heading" colspan="2" style="height:50px;font-size:16px;">Order Receipt - Order Number <?= isset($orderid)?$orderid:null?></td> 
	</tr>
	<tr>
		<td>
		<span class="req">
		 Please print this page and retain it for your own records. <br/>
		 Your international purchase may carry local import fees and duties for which the buyer is responsible.
		 <?=(empty($create_payment_error) ? "" : "<br><span style='color:red'>Although you order successfully, but creating payment account process is fail because of duplicate transaction. Please wait few minutes and try to create payment account again.")?>
		</span>		
		</td> 
	</tr>
	
	<tr>
		<td>
			<table width="100%">
			<tr>
			<td width="50%" valign="top">
				<span class="cartsubheading">Shipping Address</span>
				<div class="hrdiv" style="height:10px;width:150px;"></div>
				<div class="paymentOptionsSummaryActualDiv">
					<?=isset($shippinginfo)?$shippinginfo->first_name.' '. $shippinginfo->last_name:null?> <br/>
					<?=isset($shippinginfo)?$shippinginfo->street_address_1:''?> <br/>
					<?=isset($shippinginfo)?$shippinginfo->street_address_2.'<br/>':''?> 
					<?=isset($shippinginfo)?$shippinginfo->city:null?>,
					<?=isset($shippinginfo)?$this->public_model->getStateName($shippinginfo->state):null?> <?=isset($shippinginfo)?$shippinginfo->zip_code:null?> <br/>
					US <br/>
					(<?=isset($shippinginfo)?substr($shippinginfo->phone_number,0,3):null?>) <?=substr($shippinginfo->phone_number,3,strlen($shippinginfo->phone_number)-1)?> <?=$shippinginfo->phone_extension?> <br/>
				</div>
			</td>
			<td width="50%" valign="top">
				<span class="cartsubheading">Billing Information</span>
				<div class="hrdiv" style="height:10px;width:150px;"></div>
				<div class="shippingPaymentOptionsActualDiv">
					<?=isset($billinginfo)?$billinginfo->first_name.' '. $billinginfo->last_name:null?> <br/>
					<?=isset($billinginfo)?$billinginfo->street_address_1:null?> <br/>
					<?=isset($billinginfo)?$billinginfo->street_address_2.'<br/>':null?>
					<?=isset($billinginfo)?$billinginfo->city:null?>, <?=isset($billinginfo)?$this->public_model->getStateName($billinginfo->state):null?> <?=isset($billinginfo)?$billinginfo->zip_code:null?> <br/>
					US <br/>
					(<?=isset($billinginfo)?substr($billinginfo->phone_number,0,3):null?>) <?=substr($billinginfo->phone_number,3,strlen($billinginfo->phone_number)-1)?> <?=$billinginfo->phone_extension?> <br/><br/>
					
				</div>
			</td>
			</tr>
			</table>
		</td> 
	</tr>
	
	<tr>
		<td>
		<span class="cartsubheading">Order Summary</span>
		<div class="hrdiv" style="height:10px;width:150px;"></div>
		
		<span class="notReq">Order Date: <?=date('m/d/Y H:i:s',strtotime($order->created))?></span> <br/>
		<span class="notReq">Payment Status: <?=isset($order)?$order->paymentStatus:null?></span> <br/>
		<?if($discount_type=='' || ($discount_type!='family' && $discount_type!='friend') ):?>
		<span class="notReq">Selected Organization Option: <?=isset($orgoptname)?$orgoptname:null?></span> <br/>
		<span class="notReq">Selected Organization: <?=isset($fundraiser)?$fundraiser->name:null?></span> <br/>
		<span class="Req"><?=isset($order)?'$'.number_format($order->donation_amount, 2):'$0.00'?></span><span class="notReq"> of your total purchase goes to selected organization</span><br/>
		<?endif?>
		</td>
	</tr>
	<tr>
		<td align="center">			
		
			<table width="90%" border="0" cellspacing="0" cellpadding="0">
				<tr>				
		   			<td width="60px"  class="tdreceiptheading" height="40px" >Quantity</td>  
		   			<td width="260px"  class="tdreceiptheading" height="40px" >Item title</td>
		   			<td width="120px" class="tdreceiptheading" height="40px" ></td>
		   			<td width="120px" class="tdreceiptheading" align="right" height="40px" >Amount</td>  
		   			<td  width="120px" align="right" class="tdreceiptheading" height="40px" >Total</td>  
		 		</tr>
 		
				<?php foreach($this->cart->contents() as $items): ?>
						<?php
						if($items['seller_type']==$dobaseller){
							$item = new stdClass();
							$item->item_id = $items['item_import_id'];
							$item->quantity = $items['qty'];
							array_push($array_items,$item);
						}
							
						?>
				<tr class="summaryContenttd ">
					
					<td align="center"><?=$items['qty']?></td>					
					<td align="left">
						<span class="orderSummaryItemDescription"><?=$items['name']?></span>
						<br/>
						<?php if ($this->cart->has_options($items['rowid']) == TRUE): ?>  

							    <p>  
							    <?php foreach ($this->cart->product_options($items['rowid']) as $option_name => $option_value): ?>  
							    
							    <span class='customType'><?php echo $option_name; ?></span>: <?php echo $option_value; ?><br />  
							    
							    <?php endforeach; ?>  
							    </p>  
				    
				    <?php endif; ?><br/>
				    <?php if($items['seller_id']!=1):?>
				    Sold by 
				    <?php echo '<a href="'. base_url(). 'store/'. $this->commonutils->convertForUrl($items['sellername']). '/' . $items['seller_id']. '" target="_Blank">'. $items['sellername']. '</a>'; ?>
				    <?php endif; ?>  
					</td>
					<td ><img src="<?=$items['image_url']?>?maxX=100&maxY=100" class="scaleCartImage" title="<? $items['name'] ?>  image" /></td >
					<td class="orderSummaryPriceCell">$<?php
						if($discount_type!=''){
							if($discount_type=='family'){
								echo $this->cart->format_number($items['cost']);
							}else if($discount_type=='friend'){
								echo $this->cart->format_number($items['adjusted_cost']);
							}else{
								echo $this->cart->format_number($items['price']);
							}
						}else{
							echo $this->cart->format_number($items['price']);	
						}
					?></td>  
					<td  class="orderSummaryPriceCell" >$<?php
						if($discount_type!=''){
							if($discount_type=='family'){
								echo $this->cart->format_number($items['qty']*$items['cost']);
							}else if($discount_type=='friend'){
								echo $this->cart->format_number($items['qty']*$items['adjusted_cost']);
							}else{
								echo $this->cart->format_number($items['qty']*$items['price']);
							}
						}else{
							echo $this->cart->format_number($items['qty']*$items['price'])	;
						} 
						
					?></td>
				</tr>
				<?endforeach?>				
			</table>
			<br/>
			<table width="90%" style="background-color: #F2F2F9;"  >
				<tr class="totalPrice"><td  align="right">Sub Total:</td><td width="100px">$<?=number_format($order->subtotal,2,'.',',')?></td></tr>
				<tr class="totalPrice"><td  align="right">Shipping & Handling:</td><td width="100px">$<?=number_format($order->shipping,2,'.',',')?></td></tr>
				<tr class="totalPrice"><td  align="right">Tax:</td><td width="100px">$<?=number_format($order->tax,2,'.',',')?></td></tr>
				<tr class="totalPrice">					
					<td align="right">GRAND TOTAL:</td>
					<td width="100px">$<?=number_format($order->total,2,'.',',')?></td>
				</tr>				
			</table>
			
			<br/>
			<table width="90%" >
				<tr>					
					<td align="center"><a class="subbutton" href="javascript:window.print();">Print Receipt</a></td>
					
				</tr>
			</table>
			
			
			
		</td> 
	</tr>
	
	
</tbody></table>
<?
$testOrder = $this->public_model->getSystemParameterValue("testOrder");
if($testOrder == "NO") {
 ?>
 	<?if($order->sentEmail==0):?>
 	<?php $this->public_model->updateSendMailForOrder($order->id);?>
<script>
	var orderid=<?=$order->id?>;
	var urldefault=$("#urldefault").val();
	var array_items=<?=json_encode($array_items)?>;
	var shippinginfo=<?=json_encode($shippinginfo)?>;
	shippinginfo=JSON.stringify(shippinginfo);
	array_items=JSON.stringify(array_items);
	$.post(urldefault + 'shoppingcart_ajax/createOrderDoBa', {'orderid':orderid,'array_items':array_items,'shippinginfo':shippinginfo}, function(data){
		$("#dv_org").html(data);
	});
</script>
	<? endif?>
<?
}
	$this->cart->destroy();
?>	